package com.xagcdx.group1.web;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.xagcdx.group1.bean.Depart;
import com.xagcdx.group1.service.DepartService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author grou1
 * @since 2020-06-09
 */
@RestController
@RequestMapping("/depart")
public class DepartController {

	
	@Autowired
	private DepartService departService;
	
@RequestMapping("/listPage")
public String listPage(Integer limit, Integer page,String dname) {
	System.out.println(dname);
	Map<String, Object> result = new HashMap<String, Object>(10);
	result.put("count", departService.counts(page, limit));
	result.put("msg", "");
	result.put("code", 0);
	result.put("data", departService.departListPage((page - 1) * limit, limit,dname));

	return new Gson().toJson(result);

}

@RequestMapping("/update")
public String update(Depart depart) {
	boolean updateById = departService.updateById(depart);
	if(updateById) {
		return "1";
	}else {
		return "0";
	}
	
}

@RequestMapping("/add")
public String add(Depart depart) {
	boolean save = departService.save(depart);
	if(save) {
		return "1";
	}else {
		return "0";
	}
}


@RequestMapping("/remove")
public String remove(String did) {
	boolean removeById = departService.removeById(did);
	if(removeById) {
		return "1";
	}else {
		return "0";
	}
	
}
@RequestMapping("/list")
public String list() {
	return new Gson().toJson(departService.list(null));
}

}

